package com.aliengen.thingple.thingple.fragment.dummy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * This class is part of the Thingple mobile application for the CMC168 Handheld reader.
 *
 * Copyright AlienGen Limited 2016. All rights reserved.
 *
 * @author Timothé Mermet-Buffet <tim@aliengen.com>
 */
public class DummyContent {

    /**
     * An array of sample (dummy) items.
     */
    public static final List<CylinderItem> ITEMS = new ArrayList<CylinderItem>();

    /**
     * A map of sample (dummy) items, by ID.
     */
    public static final Map<String, CylinderItem> ITEM_MAP = new HashMap<String, CylinderItem>();

    private static final int COUNT = 25;

    static {
        // Add some sample items.
        /*
        for (int i = 1; i <= COUNT; i++) {
            addItem(createCylinderItem(i));
        }
        */
    }

    public static void generate()
    {
        if(ITEMS.isEmpty()) {
            for (int i = 1; i <= COUNT; i++) {
                addItem(createCylinderItem(i));
            }
        }
    }

    private static void addItem(CylinderItem item) {
        ITEMS.add(item);
        ITEM_MAP.put(item.id, item);
    }

    private static CylinderItem createCylinderItem(int position) {
        return new CylinderItem(String.valueOf(position), "Cylinder " + position, makeDetails(position), "OK");
    }

    private static String makeDetails(int position) {
        StringBuilder builder = new StringBuilder();
        builder.append("Details about Item: ").append(position);
        for (int i = 0; i < position; i++) {
            builder.append("\nMore details information here.");
        }
        return builder.toString();
    }

    /**
     * A cylinder item representing a piece of content.
     */
    public static class CylinderItem {
        public final String id;
        public final String reference;
        public final String status;
        public final String details;

        public CylinderItem(String id, String reference, String details, String status) {
            this.id = id;
            this.reference = reference;
            this.details = details;
            this.status = status;
        }

        @Override
        public String toString() {
            return reference;
        }
    }
}
